home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’96 / Sessions ’96 / ODF- Easy OpenDoc / MacHack(4) / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-06-18  |  6.1 KB  |  229 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef PART_H
  11. #include "Part.h"
  12. #endif
  13.  
  14. #ifndef DEFINES_K
  15. #include "Defines.k"
  16. #endif
  17.  
  18. #ifndef BINDING_K
  19. #include "Binding.k"
  20. #endif
  21.  
  22. #ifndef FWABOUT_H
  23. #include "FWAbout.h"
  24. #endif
  25.  
  26. // ----- Framework Includes -----
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWCFMRES_H
  33. #include "FWCFMRes.h"
  34. #endif
  35.  
  36. #ifndef FWSHAPE_H
  37. #include "FWShape.h"
  38. #endif
  39.  
  40. //========================================================================================
  41. //    Runtime informations
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment machack
  46. #endif
  47.  
  48. //========================================================================================
  49. //    CLASS CMacHackPart
  50. //========================================================================================
  51.  
  52.  
  53. FW_DEFINE_AUTO(CMacHackPart)
  54.     
  55. //----------------------------------------------------------------------------------------
  56. //     CMacHackPart::CMacHackPart
  57. //----------------------------------------------------------------------------------------
  58.  
  59. CMacHackPart::CMacHackPart(ODPart* odPart):
  60.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  61.     fGeometry(cRectangle)
  62. {
  63.     fShapes[0] = fShapes[1] = fShapes[2] = NULL;
  64.     CreateShapes();
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //     CMacHackPart::~CMacHackPart
  69. //----------------------------------------------------------------------------------------
  70.  
  71. CMacHackPart::~CMacHackPart()
  72. {
  73.     DeleteShapes();
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //     CMacHackPart::Initialize
  78. //----------------------------------------------------------------------------------------
  79.  
  80. void CMacHackPart::Initialize(Environment* ev)
  81. {
  82.     FW_CPart::Initialize(ev);
  83.     
  84.     fPresentation = RegisterPresentation(ev, "Apple:Presentation:MacHack", TRUE);
  85.     
  86.     // ----- Initialize my menu -----
  87.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //     CMacHackPart::NewFrame
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CFrame* CMacHackPart::NewFrame(Environment* ev, 
  95.                                   ODFrame* odFrame, 
  96.                                   FW_CPresentation* presentation, 
  97.                                   FW_Boolean fromStorage)
  98. {
  99. FW_UNUSED(presentation);
  100. FW_UNUSED(fromStorage);
  101.     
  102.     return FW_NEW(FW_CFrame, (ev, odFrame, presentation, this, kMacHackView));
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //     CMacHackPart::NewPartContent
  107. //----------------------------------------------------------------------------------------
  108.  
  109. FW_CContent* CMacHackPart::NewPartContent(Environment* ev)
  110. {
  111.     return NULL;
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CMacHackPart::DoMenu
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_Boolean CMacHackPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  119. {
  120.     FW_Boolean result = TRUE;
  121.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  122.  
  123.     switch (commandID)
  124.     {
  125.         case kODCommandAbout:
  126.             ::FW_About(ev, this, kAbout);
  127.             break;
  128.         
  129.         case cRectangle:
  130.         case cOval:
  131.         case cRoundRect:
  132.             ChangeGeometry(ev, commandID);
  133.             break;
  134.             
  135.         default:
  136.             result = false;        
  137.     }
  138.     
  139.     return result;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    CMacHackPart::DoAdjustMenus
  144. //----------------------------------------------------------------------------------------
  145.  
  146. FW_Boolean CMacHackPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  147. {
  148.     if (hasMenuFocus)
  149.     {
  150.         menuBar->EnableAndCheckCommand(ev, cRectangle, TRUE, fGeometry == cRectangle);
  151.         menuBar->EnableAndCheckCommand(ev, cOval,  TRUE, fGeometry == cOval);
  152.         menuBar->EnableAndCheckCommand(ev, cRoundRect,  TRUE, fGeometry == cRoundRect);
  153.     }
  154.     
  155.     return false;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    CMacHackPart::ChangeGeometry
  160. //----------------------------------------------------------------------------------------
  161.  
  162. void CMacHackPart::ChangeGeometry(Environment* ev, ODCommandID geometry)
  163. {
  164.     if (geometry != fGeometry)
  165.     {
  166.         fGeometry = geometry;
  167.         
  168.         DeleteShapes();
  169.         CreateShapes();
  170.         
  171.         FW_CScreenContext sr(ev);
  172.         
  173.         FW_CRect bounds;
  174.         for (short i = 0; i < 3; i++)
  175.         {
  176.             fShapes[i]->GetBounds(sr, bounds);
  177.             fPresentation->Invalidate(ev, bounds);
  178.         }
  179.     }
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    CMacHackPart::DeleteShapes
  184. //----------------------------------------------------------------------------------------
  185.  
  186. void CMacHackPart::DeleteShapes()
  187. {
  188.     for (short i = 0; i < 3; i++)
  189.         delete fShapes[i];    
  190.  
  191.     fShapes[0] = fShapes[1] = fShapes[2] = NULL;
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    CMacHackPart::CreateShapes
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void CMacHackPart::CreateShapes()
  199. {
  200.     FW_CPlatformRect plfmRect(20, 50, 120, 150);
  201.     FW_CRect rect(plfmRect);
  202.     
  203.     FW_CInk blue(FW_kRGBBlue);
  204.     FW_CInk white(FW_kRGBWhite);
  205.     FW_CInk red(FW_kRGBRed);
  206.     
  207.     switch (fGeometry)
  208.     {
  209.         case cRectangle:
  210.             fShapes[0] = FW_NEW(FW_CRectShape, (rect, FW_kFill, blue));
  211.             break;
  212.         case cOval:
  213.             fShapes[0] = FW_NEW(FW_COvalShape, (rect, FW_kFill, blue));
  214.             break;
  215.         case cRoundRect:
  216.             fShapes[0] = FW_NEW(FW_CRoundRectShape, (rect, FW_CPoint(FW_IntToFixed(16), FW_IntToFixed(16)), FW_kFill, blue));
  217.             break;    
  218.     }
  219.     
  220.     
  221.     fShapes[1] = fShapes[0]->Copy();
  222.     fShapes[1]->MoveShape(FW_IntToFixed(120), FW_kFixed0);
  223.     fShapes[1]->SetInk(white);
  224.     
  225.     fShapes[2] = fShapes[1]->Copy();
  226.     fShapes[2]->MoveShape(FW_IntToFixed(120), FW_kFixed0);
  227.     fShapes[2]->SetInk(red);
  228. }
  229.